
<?php
// 分类列表
  ob_clean();

  //分类列表数据重组
  $cate = array();

  $pid = !empty($_GET['id'])?$_GET['id']:0;

  //树状型列表
  // $sql = "select * from `cate` where pid=$pid";
  // $result = mysqli_query($link,$sql);

  // while ($arr = mysqli_fetch_assoc($result)){
  //   $cate[] = $arr;
  // }

  $cate = getSelect('cate',"pid=$pid");

  // 判断是否是ajax请求
  if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

    echo json_encode($cate);die;
  }
// print_r($cate);die;

// /*递归列表   （核心：调用自身）*/
//   $cate = getCate();

//加载后台公共视图
 include (View_PATH.$admin.'/communal.html');


/*原生代码
  //查询语句
  $sql = "select * from `cate` where pid=0 ";

  //执行语句
  $result = mysqli_query($link,$sql);

  //提取真值
  while( $arr = mysqli_fetch_assoc($result)){

    $cate[]=$arr;
    $one=$arr['id'];

    $sql = "select * from `cate` where pid=$one";

    $result1 = mysqli_query($link,$sql);

    while( $arr1 = mysqli_fetch_assoc($result1)){

      $cate[]=$arr1;
      $two=$arr1['id'];

      $sql = "select * from `cate` where pid=$two";
      $result2 = mysqli_query($link,$sql);

      while( $arr2 = mysqli_fetch_assoc($result2)){

        $cate[]=$arr2;
      }

    }

  }
  print_r($cate);die;*/


/*//用函数封装

  $cate = getCate();

  function getCate($pid=0,$cate=array()){

    $sql = "select * from `cate` where pid=$pid ";

    $result = mysqli_query($GLOBALS['link'],$sql);

    while ($arr=mysqli_fetch_assoc($result)){

      $cate[] = $arr;
      $cate = getCate2($arr['id'],$cate);

    }
    return $cate;
  }

  function getCate2($pid=0,$cate=array()){

    $sql = "select * from `cate` where pid=$pid ";

    $result2 = mysqli_query($GLOBALS['link'],$sql);

    while ($arr1=mysqli_fetch_assoc($result2)){

      $cate[] = $arr1;
      $cate = getCate3($arr1['id'],$cate);

    }
    return $cate;
  }

  function getCate3($pid=0,$cate=array()){

    $sql = "select * from `cate` where pid=$pid ";

    $result3 = mysqli_query($GLOBALS['link'],$sql);

    while ($arr2=mysqli_fetch_assoc($result3)){

      $cate[] = $arr2;


    }
    return $cate;
  }
// print_r($cate);die;*/





?>

